import React, { Component } from 'react'
// import IceContainer from '@icedesign/container';
import DataBinder from '@icedesign/data-binder';
import { GetUrlParam, LoginReq } from '../../../baseConfig';
import { Loading, Table, Icon } from '@icedesign/base';
// import './BoardBox.scss';

@DataBinder({
  BoardBoxData: {
    url: `${global.constants.GOLDEYEGETHOST}cattle/index_info`,
    type: 'get',
    params: {},
    defaultBindingData: {}
  },
})
export default class BoardBox extends Component {

  static propTypes = {
    // secu_code: PropTypes.string.isRequired,
    // type: PropTypes.string,
  };
  
  constructor(props) {
    super(props);
    // console.log("props",props)
    this.state = {
      newData:[],
      // baoxiangongsi:[],
      placards_tips:[],
      placards_data:[],
      sum:{}
    }
  }
  
  componentDidMount() {
    this.props.updateBindingData('BoardBoxData',{
      params: {
        secu_code:GetUrlParam("secu_code"),
      }
    }, (data) => {
      // console.log('获取到tab的data',data.data.placards_tips)
      if(data.flag){
        // console.log("data",data.data)
        this.setState({
          placards_tips:data.data.placards_tips
        });
        this.pushArray(this.state.placards_tips);
      }else{
        this.setState({
          message: true
        })
      }
    });
  }

  getCellProps = (rowIndex,colIndex) => {
    const ret = {
      colSpan: 1,
      rowSpan: this.state.sum[`'${rowIndex}'`] && colIndex === 0 ? this.state.sum[`'${rowIndex}'`] : 1
    }
    return ret
  }

  pushArray = (data) => {
    let nm =[];
    let datas = [];
    let sum = {};
    let currentKey;

    nm.push(data.baoxiangongsi,data.chanyeziben,data.simujijin)
    // console.log("nm",nm)
    for(let i=0;i<nm.length;i++){
      for(let j=0;j<nm[i].value_list.length;j++){
        if (j === 0){
          currentKey = `'${datas.length}'`
          sum[currentKey] = 1
        } else {
          sum[currentKey] ++
        }
        datas.push({index_type:`${nm[i].index_type}`,index_name:`${nm[i].value_list[j].index_name}`,index_range:`${nm[i].value_list[j].index_range}`,index_value:`${nm[i].value_list[j].index_value}`,index_flag:`${nm[i].value_list[j].index_flag}`})
      }
    }

    this.setState({
      placards_data:datas,
      sum:sum
    })
    // console.log("datas",this.state.placards_data);
  }

  cellRender = (value,index,record) => {
    // console.log("record",record.index_flag)
    if(record.index_flag==="down"){
      return(
        <img src="./assetc/down.png" />
      // <Icon type="ascending" style={{color:'#F6434C'}} />
      )
    }else{
      return(<img src="./assetc/up.png" />)
    }
  }

  render() {
    return (
      <div style={{margin:'30px'}}>
        <Table dataSource={this.state.placards_data} getCellProps={this.getCellProps} >
          <Table.Column align="center" title="机构" dataIndex="index_type" />
          <Table.Column align="center" title="指标" dataIndex="index_name" />
          <Table.Column align="center" title="指标值"  dataIndex="index_value" />
          <Table.Column align="center" title="范围" dataIndex="index_range" />
          <Table.Column align="center" title="风险"  dataIndex="index_flag" cell={this.cellRender}/>
        </Table>
      </div>
    )
  }
}
